package com.codeoss.framework.view.renderer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.expression.Expression;
import com.codeoss.framework.expression.IScriptService;
import com.codeoss.framework.expression.IScriptServiceStore;
import com.codeoss.framework.util.StringUtils;
import com.codeoss.framework.view.component.Component;
import com.codeoss.framework.view.component.Icon;

@Service
public class IconRenderer extends CommonComponentRenderer {
	@Autowired
	private IScriptServiceStore ScriptServiceStore;
	protected void startRenderView(YunContext yunContext, Component component, ViewSerializeMap viewSerializeMap) {
		super.startRenderView(yunContext, component, viewSerializeMap);
		Icon icon=(Icon)component;
		viewSerializeMap.put("iconClass", icon.getIconClass());
		Expression cssStyleExpression=component.getCssStyleExpression();
		if(cssStyleExpression!=null) {
			IScriptService scriptService=ScriptServiceStore.getScriptService(cssStyleExpression);
			String cssStyle=(String)scriptService.eval(cssStyleExpression.getScript(), yunContext.getVarValueMap());
			viewSerializeMap.put("cssStyle", cssStyle);
		}
		String confirmMessage=icon.getConfirmMessage();
		if(!StringUtils.isEmpty(confirmMessage)) {
			viewSerializeMap.put("confirmMessage", confirmMessage);
		}
	}
}
